$(function () {
	
	    
		$('#box').datagrid({
		url : 'http://localhost:8080/Sorrow/list.do',
		width : 1000,
		
		
		
		title : 'National Football Cup Schedule Auto Springs',
		columns : [[
        {
	    field : 'round',
	    title : 'Round',
	    width : 20,
	    align: 'center',
	    formatter: function(value,row,index){
			  return "第<strong>"+row.round+"</strong>轮";  	}
	    },
	    
		{
		field : 'teamleft',
		title : 'Team At Home',
		width: 50, 
		align: 'center',
		formatter: function(value,row,index){
	    	  if(row.teamleft=='null'){
			  return "<strong>--</strong>"; 
	    	  }else{
	    	  return "<strong>"+row.teamleft+"</strong>"; 
	    	  }
	    	  }
		},
		{
			field : 'vs',
			title : 'VS',
			width: 10, 
			align: 'center',
			 formatter: function(value,row,index){
			  return "<strong>VS</strong>";  	}
		},
		{
		field : 'teamright',
		title : 'Team Be Away',
		width: 50, 
		align: 'center',
		formatter: function(value,row,index){
	    	  if(row.teamright == 'null'){
			  return "<strong>--</strong>"; 
	    	  }else{
	    	  return "<strong>"+row.teamright+"</strong>"; 
	    	  }
	    	  }
		},
	
		{
			field : 'time',
			title : 'Match Time',
			width: 50, 
			align: 'center',
			},
		]],
		pagination : true,
        //idField : 'id',
		fitColumns : "true",
		pageSize : 10,
		pageList : [5,10, 20],
		toolbar : "#toolbar",
		rownumbers : "true",
		//singleSelect : "false",
		//checkOnSelect : "false",
		 checkOnSelect: false, 
		 selectOnCheck: false,
		
		
		});
		
	
	    
	});
	
	
	
		  
		  
    function destroyUser(){
	var row = $('#box').datagrid('getSelected');//json ��ʽ {"teamname":"England","teamnumber":"1"} 
	 
	//选中多行
	var rows = $('#box').datagrid('getSelections'); 
	for(var i=0; i<rows.length; i++){  
	   // alert(rows[i].teamname);
	}  
	
	//选中复选框
	var check =  $('#box').datagrid('getChecked');
	if(check){
		alert(JSON.stringify(check));
	}


	
	if (row){
		$.messager.confirm('Confirm','Are you sure you want to destroy this team?',function(r){
			
			if(r){
				
				for(var i=0; i<rows.length; i++){  
					var tiny = rows[i].teamname;
				 

				$.ajax({  
                type: "GET",  
                url: "http://localhost:8080/Myeclips_Pagesplit/destroy.do?tn="+tiny,  
                cache: false,  
                dataType : "text",  
                success: function(data){  
				 if(data == 1){
					 $.messager.show({	
							title: 'Destory Success',
							msg: "Congratulations!"
						});
					 $('#box').datagrid('reload');
					 
					 
				 }
                }  
                
                 });   
				
                         }
			}
			
		});
		
	}
}


function newUser(){
	$('#dlg').dialog('open').dialog('setTitle','New User');
	$('#fm').form('clear');
	
	url = 'http://localhost:8080/Myeclips_Pagesplit/add.do';
}


function saveUser(){
	$('#fm').form('submit',{
		url: url,
		onSubmit: function(){
			return $(this).form('validate');
		},
		success: function(result){
			//alert(result);
			if (result == 1){
				
				$('#dlg').dialog('close');  
				$.messager.show({
				title: 'Success',
				msg: "Congratulations!"
				});
			    $('#box').datagrid('reload');	
			} else{
				$.messager.show({
				title: 'Error',
				msg: "Action Failed!!"
				});
			}
		}
	});
}


function editUser(){
	var row = $('#box').datagrid('getSelected');
	//alert(row.teamname);
	if (row){
		$('#dlg').dialog('open').dialog('setTitle','Edit User');
		//$('#fm').form('load',row);
		$("#fmteamnum").val(row.teamnumber);
		$("#fmteamname").val(row.teamname);
		//$("#fmteamnum").attr('disabled','disabled');
		//alert(row.teamname);
		url = 'http://localhost:8080/Myeclips_Pagesplit/edit.do?tn='+row.teamname;
		}
}

function searchUser(){
	
	   
	/*$('#checkfm').form('submit',{
		url : 'http://localhost:8080/Myeclips_Pagesplit/show.do',
		url : null,
       
		onSubmit: function(){
		
		$('#box').datagrid('loadData',{ total: 0, rows: [] });
		return $(this).form('validate');
		},
		success: function(result){
			
			if (result){
				//$('#box').datagrid('loadData',result);
				alert(result);
                
				/*$('#box').datagrid('load', { 

				searchname: $("#checkname").val(), 

				searchnumber: $("#checknumber").val() 

				}); */
				/*$('#box').datagrid({
					
				url : "http://localhost:8080/Myeclips_Pagesplit/search.do?searchname="+$("#checkname").val()+"&searchnumber="+$("#checknumber").val()+""
				});
				
				
			} else{
				$('#box').datagrid('loadData',{ total: 0, rows: [] });
				$.messager.show({
				title: 'Error',
				msg: "No record checked!!"
				});
			}
		}
	});
	*/
    /*$('#box').datagrid({
		url : "search_json.jsp?searchname="+$("#checkname").val()+"&searchnumber="+$("#checknumber").val()+"String page,String rows" 
	});
	$('#box').datagrid('reload');	*/

	
	$.ajax({
		type : 'get',
		url : "http://localhost:8080/Myeclips_Pagesplit/search.do?searchname="+$("#checkname").val()+"&searchnumber="+$("#checknumber").val()+"&page=1&rows=10",
		async : true,
		dataType : 'json',
		success : function(data) {
		       
			    
				$('#box').datagrid({
					
					url : "http://localhost:8080/Myeclips_Pagesplit/search.do?searchname="+$("#checkname").val()+"&searchnumber="+$("#checknumber").val()+""
					});
			
				

			if(data == null){
				$('#box').datagrid('loadData',{ total: 0, rows: [] });
				$.messager.show({
				title: 'Error',
				msg: "No record checked!!"
				});
			}
		}
	});
	
	
	
}

function rebornooo(){
	$('#box').datagrid({
		url : 'http://localhost:8080/Myeclips_Pagesplit/show.do'
	});
}


function showjson(){
	
	   

	
	$.ajax({
		type : 'get',
		url : 'http://localhost:8080/Myeclips_Pagesplit/show.do?page=5&rows=10',
		async : true,
		dataType : 'json',
		success : function(data) {
		alert((JSON.stringify(data)));
		}
	});
	
	
	
}

function reborn(){
	
	$.messager.confirm('Confirm','Are you sure you want to refresh schedule?',function(r){
		
		if(r){
	$.ajax({
		type : 'get',
		url : 'http://localhost:8080/Sorrow/schedule.do',
		async : true,
		dataType : 'json',
		success : function(data) {
		if(data =='1'){
			$.messager.show({
				title: 'Great',
				msg: "Has Auto Refreshed The Schedule"
				});
			$('#box').datagrid('reload');	
		}
		}
	});
		}
	});
	










}

function hrefto(){
	location.href = "http://localhost:8080/Myeclips_Pagesplit/";
}
